/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef BROADCOM_EGRESS_H
#define BROADCOM_EGRESS_H

#include <cassert>
#include <queue>
#include "ns3/packet.h"
#include "ns3/queue.h"
#include "ns3/drop-tail-queue.h"
#include "ns3/point-to-point-net-device.h"
#include "ns3/event-id.h"

namespace ns3 {

class TraceContainer;

class BEgressQueue : public Queue<Packet> {
 public:
    static TypeId GetTypeId(void);
    static const unsigned qCnt = 8;  // max number of queues, 8 for switches
	BEgressQueue();
	virtual ~BEgressQueue();
	bool Enqueue(Ptr<Packet> p, uint32_t qIndex);
	Ptr<Packet> DequeueRR(bool paused[]);
	uint32_t GetNBytes(uint32_t qIndex) const;
	uint32_t GetNBytesTotal() const;
	uint32_t GetLastQueue();

private:
	bool DoEnqueue(Ptr<Packet> p, uint32_t qIndex);
	Ptr<Packet> DoDequeueRR(bool paused[]);
	//for compatibility
	virtual bool Enqueue(Ptr<Packet> p) override;
	virtual Ptr<Packet> Dequeue(void) override;
	virtual Ptr<Packet> Remove (void) override;
	virtual Ptr<const Packet> Peek(void) const override;

	// variables
	double m_maxBytes;  // total bytes limit
	uint32_t m_bytesInQueue[qCnt];
	uint32_t m_bytesInQueueTotal;
	uint32_t m_rrlast;
	uint32_t m_qlast;
	std::vector<Ptr<Queue> > m_queues;  // uc queues

	TracedCallback<Ptr<const Packet>, uint32_t> m_traceBeqEnqueue;
	TracedCallback<Ptr<const Packet>, uint32_t> m_traceBeqDequeue;

	NS_LOG_TEMPLATE_DECLARE;     //!< redefinition of the log component
};

} // namespace ns3

#endif /* BROADCOM_EGRESS_H */
